
import Vue from 'vue'
import variables from '@/assets/styles/element-variables.scss'
import defaultSettings from '@/settings'

const { theme, sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle } = defaultSettings

const state = {
  title: '',
  theme: theme,
  sideTheme: sideTheme,
  showSettings: showSettings,
  topNav: topNav,
  tagsView: tagsView ,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  dynamicTitle: dynamicTitle
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if(!key || value==null || value == undefined){
      return ;
    }
    if (state.hasOwnProperty(key)) {
      state[key] = value
      Vue.ls.set(key, value);
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  },
  
  // 设置网页标题
  setTitle({ commit }, title) {
    state.title = title
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
